package apiday02.object;

import java.util.Objects;

public class EqualsDemo {
	public static void main(String[] args) {
		Cell c1 = new Cell(3,4);
		Cell c2 = new Cell(3,4);
		//c1 c2 内部数据 x,y 是完全一样的， 是数据一样的对象，相等的对象
		//== 仅仅比较变量的值，这里的值是引用的对象地址，地址一样返回true
		//地址不一样得到false。 == 不能用来比较对象数据相等
		System.out.println(c1 == c2);
		System.out.println(c1.equals(c2));
	}
}
class Cell{
	int x,y;
	public Cell(int x, int y) {
		super();
		this.x = x;
		this.y = y;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		Cell cell = (Cell) o;
		return x == cell.x && y == cell.y;
	}
}




